package monitor

import (
    "encoding/json"
    "fmt"
    "os"
    
)

type Region struct {
	Enabled			bool
	Name			string
	CmdPid			uint16
	Logicid			string
	CmdIp			string
	PgIp			string
	FilePath		string
	WriteLogEable	bool
	WriteMp3Eable	bool
}

type Cfg struct {
    Enabled bool
	Regions []Region
}


var UserCfg Cfg

var cfile = "conf.json"

func printCfg() {
	fmt.Printf("读取配置文件\"%s\"成功\r\n", cfile)
//	fmt.Printf("Manufacturers\t: 0x%08X\r\n", UserCfg.Manufacturers)
//	fmt.Printf("Product\t\t: 0x%08X\r\n", UserCfg.Product)
//	fmt.Printf("Boot\t\t: %s\t0x%08X\r\n", UserCfg.Bin[0].FileName, UserCfg.Bin[0].Addr)
//	fmt.Printf("App0\t\t: %s\t0x%08X\r\n", UserCfg.Bin[1].FileName, UserCfg.Bin[1].Addr)

	for n, d := range UserCfg.Regions {
		if d.Enabled {
			fmt.Printf("#%d : %s\r\n",n ,d.Name)
		}
    }
}

func init() {
    fd, err := os.Open(cfile)
	if err != nil {
		fmt.Println("open faild", cfile)
		os.Exit(1)
	}
    defer fd.Close()
    decoder := json.NewDecoder(fd)
    err = decoder.Decode(&UserCfg)
    if err != nil {
        fmt.Println("parse faild", cfile)
		os.Exit(1)
    }

    fmt.Println(UserCfg)
    printCfg()
}

